import smtplib
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr


def send_email(account_info, to_addr):
    def _format_addr(s):
        name, addr = parseaddr(s)
        return formataddr((Header(name, 'utf-8').encode(), addr))

    smtpObj = smtplib.SMTP('smtp.qq.com', 587)
    smtpObj.ehlo()
    smtpObj.starttls()
    smtpObj.login('991777908@qq.com', 'albbhasvyepzbede')

    from_addr = '991777908@qq.com'
    message = MIMEText('您的账号信息为: {}'.format(account_info), 'plain', 'utf-8')
    message['From'] = _format_addr('DJ <%s>' % from_addr)
    message['To'] = _format_addr('消息接收者 <%s>' % to_addr)
    subject = '账号信息推送'
    message['Subject'] = Header(subject, 'utf-8')

    smtpObj.sendmail(from_addr, [to_addr], message.as_string())
    smtpObj.quit()